package com.sqx.modules.health.controller;

import com.sqx.modules.health.common.Constants;
import com.sqx.modules.health.common.Result;
import com.sqx.modules.health.entity.Record;
import com.sqx.modules.health.service.IRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.Map;

/**
 * <p>
 * 康复方案表 前端控制器
 * </p>
 *
 * @author hsx
 * @since 2022-08-30
 */

@Api(value = "测量记录表", tags = "测量记录接口", description = "")
@RestController
@RequestMapping("/health/app/record")
public class AppRecordController {
    @Autowired
    private IRecordService recordService;

    // 新增或更新
    @ApiOperation(value = "新增或更新康复方案表", notes = "新增或更新康复方案表")
    @PostMapping("/save")
    public Result patientPassword(@RequestBody Record record) {
        record.setFlag(1);
        boolean update = recordService.save(record);
        if (update) {
            return Result.success("上报成功");
        } else {
            return Result.error(Constants.CODE_500, "上报失败");
        }
    }

    @ApiOperation(value = "新增或更新康复方案表", notes = "新增或更新康复方案表")
    @PostMapping("/webSave")
    public Result webSave(@RequestParam Map<String, String> params) {
        String glucose = params.get("glucose");
        String recordTime = params.get("recordtime");
        String type = params.get("type");
        String uid = params.get("uid");
        String doctorid = params.get("doctorid");
        String doctorname = params.get("doctorname");

        Record record = new Record();
        record.setUid(Long.valueOf(uid));
        record.setType(Integer.valueOf(type));
        record.setGlucose(new BigDecimal(glucose));
        record.setRecordtime(recordTime);
        record.setDoctorid(Long.valueOf(doctorid));
        record.setDoctorname(doctorname);

        record.setFlag(1);
        boolean update = recordService.save(record);
        if (update) {
            return Result.success("上报成功");
        } else {
            return Result.error(Constants.CODE_500, "上报失败");
        }
    }

}

